<extend name="common:commonNewerTemplate" />
<block name="main_content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="index.html"
				data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
			<a href="#">经销商</a> <a class="current" href="#">经销商后返余额</a>
		</div>
		
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
						<h5>搜索条件（仅支持搜索单用户）</h5>
					</div>
					<div class="widget-content nopadding">
						<form novalidate="novalidate" id="basic_validate"
							name="basic_validate" action="#" method="post"
							class="form-horizontal">
							<div class="control-group">
								<label class="control-label">经销商编号:</label>
								<div class="controls">
									<input type="text" id="dealer_id" name="dealer_id" placeholder="推荐搜索条件"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">经销商名称:</label>
								<div class="controls">
									<input type="text" id="dealer_name" name="dealer_name" placeholder="请输入经销商全称，不支持模糊查询"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">订单日期：</label>
								<div class="controls">									
									<input id="start_date" name="start_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">-
									<input id="end_date" name="end_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">后返金额:</label>
								<div class="controls">
									<input type="text" id="dealer_cashback_amount"  readonly="readonly"/>
								</div>
							</div>
							<div class="form-actions">
								<input id="btn_search" type="button" class="btn btn-success"   value="计算">
								<input id="btn_export" type="button" class="btn btn-primary"   value="导出后返余额">
								
							</div>
						</form>
						  
					</div>
				</div>
			</div>
			
	


</div>
</div>
</block>

<block name="js_content">
<script src="../../../Public/js/laydate/laydate.js"></script>
<script>

			
$('#btn_search').bind('click', function(){
	
	var startdate = $('#start_date').val();
	var enddate	= $('#end_date').val();
	var  dealer_id = $('#dealer_id').val();
	var dealer_name=$('#dealer_name').val();
	
	if(dealer_id=="" && dealer_name==""){
		alert("经销商编号和名称不能同时为空!请检查!");
		return;
	}
	
	
	
		if(startdate ==""){
			alert("开始日期不能为空！！！");
			return ;
		}
	   			
		if(enddate ==""){
			alert("结束日期不能为空！！！");
			return ;
		}
	
		var startdates = startdate.split('-');
		var enddates = enddate.split('-');

		startdate = startdates[1] + '/' + startdates[2].split(" ")[0] + '/' + startdates[0]+" "+startdates[2].split(" ")[1] ;
				
		enddate = enddates[1] + '/' + enddates[2].split(" ")[0] + '/' + enddates[0]+" " +enddates[2].split(" ")[1];
       
		 var a = Date.parse(enddate) - Date.parse(startdate) ;
		
		 if(a < 0){
				alert("结束时间不能早于开始时间,请检查!");
				return ;
			}else{
				 a = a/(24*3600*1000.0);
				if(a >31){
					
					alert("只能计算出1个月内的经销商后返余额!请检查日期!");
					return ;
				}
				
			}
	 $('#dealer_cashback_amount').val('');
	 var condition = $("#basic_validate").serialize();
     
     $.ajax({
         type: 'post',
         url: '/AjaxService/center/dealer/calcDealerCashBackAmount',
         data: condition,
         dataType: 'json',
         async: false,
         success: function (data) {
        	 if (data.IsSuccess == 0) {
                 alert(data.ErrorMsg);
                 return;
             } else {
            	 $('#dealer_cashback_amount').val(data['Result']);
               
             }
        	 
       

         },
         error: function (e, err_name, err_text) {

         }
     });

	
	
});
		
		


$('#btn_export').bind('click', function(){
    //var order_status	= $('#order_status').val();
    //var payment_status	= $('#payment_status').val();
    /* if(order_status != 22 || payment_status != 1){
        alert('订单状态需选“已支付”，支付状态需选“已支付”');
        return;
    } */
    
	var startdate	= $('#start_date').val();
	var enddate	= $('#end_date').val();
	
		if(startdate ==""){
			alert("开始日期不能为空！！！");
			return ;
		}
	   			
		if(enddate ==""){
			alert("结束日期不能为空！！！");
			return ;
		}
	
		var startdates = startdate.split('-');
		var enddates = enddate.split('-');

		startdate = startdates[1] + '/' + startdates[2].split(" ")[0] + '/' + startdates[0]+" "+startdates[2].split(" ")[1] ;
				
		enddate = enddates[1] + '/' + enddates[2].split(" ")[0] + '/' + enddates[0]+" " +enddates[2].split(" ")[1];
       
		 var a = Date.parse(enddate) - Date.parse(startdate) ;
		
		 if(a < 0){
				alert("结束时间不能早于开始时间,请检查!");
				return ;
			}else{
				 a = a/(24*3600*1000.0);
				if(a >31){
					
					alert("只能导出1个月内的经销商后返余额单!请检查日期!");
					return ;
				}
				
			}
		
		
    var export_url = '/dealer/shipDealerCashBackAmountExcel?' + $("#basic_validate").serialize();
    window.open(export_url);
});
	
</script>
</block>